package com.eusun.design.state.demo1;

public class SoldState implements State {
    private final GumballMachine machine;

    public SoldState(GumballMachine machine) {
        this.machine = machine;
    }

    @Override
    public void insertQuarter() {
        System.out.println("Please wait, we're already giving you a gumball");
    }

    @Override
    public void ejectQuarter() {
        System.out.println("Sorry, you already turned the crank");
    }

    @Override
    public void turnCrank() {
        System.out.println("Turning twice doesn't get you another gumball!");
    }

    @Override
    public void dispense() {
        this.machine.releaseBall();
        if (this.machine.getCount() > 0) {
            this.machine.setState(this.machine.getNoQuarterState());
        } else {
            System.out.println("Oops, out of gumballs!");
            this.machine.setState(this.machine.getSoldOutState());
        }
    }
}
